package net.jgrm.common.model;

import net.jgrm.common.util.ResultUtils;

/**
 * 统一返回结果封装类
 *
 * @param <T> 数据类型
 * @author service-common
 */
public class Result<T> {

    /**
     * 响应码
     */
    private int code;

    /**
     * 响应消息
     */
    private String msg;

    /**
     * 响应数据
     */
    private T data;

    /**
     * 默认构造函数
     */
    public Result() {
    }

    /**
     * 构造函数
     *
     * @param code 响应码
     * @param msg  响应消息
     */
    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 构造函数
     *
     * @param code 响应码
     * @param msg  响应消息
     * @param data 响应数据
     */
    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 判断是否成功
     *
     * @return true:成功 false:失败
     */
    public boolean isSuccess() {
        return ResultUtils.SUCCESS_CODE == code;
    }

    @Override
    public String toString() {
        return "Result{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}